public class SolutionOfferII69 {
    public int peakIndexInMountainArray(int[] arr) {
        int l=1,r=arr.length-2;
        while (l<=r){
            int mid=(l+r)/2;
            if (arr[mid]>arr[mid-1]&&arr[mid]>arr[mid+1]){
                return mid;
            }
            if (arr[mid]>arr[mid-1]&&arr[mid]<arr[mid+1]){
                l=mid+1;
            }
            if (arr[mid]<arr[mid-1]&&arr[mid]>arr[mid+1]){
                r=mid-1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionOfferII69().peakIndexInMountainArray(new int[]{1,3,5,4,2}));
    }
}
